package cn.enjoy.tool.juc;

/**
 * @author K
 * @date 2021/7/30 下午3:00
 */
public class InterruptTest {

    public static void main(String[] args) {
        SleepRunner sleepRunner = new SleepRunner();
        BusyRunner busyRunner = new BusyRunner();
        Thread sleepThread = new Thread(sleepRunner, "SleepThread");
        Thread busyThread = new Thread(busyRunner, "BusyThread");
        sleepThread.start();
        busyThread.start();
        sleepThread.interrupt();
        busyThread.interrupt();
        System.out.println("SleepThread is interrupted " + sleepThread.isInterrupted());
        System.out.println("BusyThread is interrupted " + busyThread.isInterrupted());
    }

    static class SleepRunner implements Runnable {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    static class BusyRunner implements Runnable {

        @Override
        public void run() {
            while (true) {
            }
        }
    }

}
